<template>
  <!-- 上传视频 -->
  <div>
    <div class="addVideo">
      <!-- 上传视频 -->
      <el-upload
        class="avatar-uploader"
        :http-request="uploadImg"
        action="#"
        :before-upload="fileSizeLimit"
        :show-file-list="false"
      >
        <div v-if="media_url!=''">
          <video
            class="avatar"
            controls
            :src="media_url"
          ></video>
        </div>
        <div v-else>
          <svg-icon
            icon-class="upload"
            class="iconUpload"
          />
          <div
            slot="tip"
            class="el-upload__tip"
          >点击上传</div>
          <div
            slot="tip"
            class="el-upload__tip"
          >支持扩展名：mp4格式</div>
        </div>
      </el-upload>
    </div>
  </div>
</template>
<script type="text/javascript">
import { uploadVideoBefore } from '@/utils/index'
export default {
  data() {
    return {
      media_url: ''
    }
  },
  watch: {

  },
  mounted() {

  },
  methods: {
    async uploadImg(params) {
      // 传到 oss 公共桶内
      params.file.mediaType = 'zhangyu-pub'
      console.log(params, 'params')
      const result = await this.uploading(params.file)
      this.$message.close()
      this.$message.success('上传成功')
      const url = result.host + '/' + result.finallName
      console.log(url, 'url')
      this.media_url = url
      this.$emit('resultUpload', url)
    },
    // 上传之前
    fileSizeLimit(file) {
      return uploadVideoBefore(file, this)
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog-footer {
  width: calc(100% - 20px);
  height: 52px;
  position: absolute;
  right: 20px;
  bottom: 20px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  justify-content: flex-end;
  .btn {
    width: 84px;
    height: 32px;
  }
}
// 添加视频
.addVideo {
  width: 100%;
  height: auto;
  padding: 0 20px;
  .input {
    margin-bottom: 20px;
  }
  .label {
    display: inline;
  }
  .inputMedia {
    width: 292px;
    margin-left: 10px;
  }
  .upload {
  }
  .upoloadIcon {
    font-size: 40px;
    margin-top: vw(30);
    margin-bottom: vw(15);
  }
}
.avatar-uploader,
.avatar {
  width: 100%;
  height: 192px;
}

::v-deep .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
::v-deep .avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
::v-deep .el-upload__tip {
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #999999;
  line-height: 20px;
  width: vw(350);
}
::v-deep .el-upload {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.iconUpload {
  font-size: 40px;
  margin-bottom: 10px;
  .el-upload__text {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(0, 0, 0, 0.65);
  }
  .el-upload__tip {
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }
}
</style>
